<?php

class HistClaimController extends Controller
{


	/**
	 * Displays a particular model.
	 * @param integer $id the ID of the model to be displayed
	 */
	public function actionView($id)
	{	
		$modelClaim=new HistClaim('search');
		$modelAnggota=new HistClaimAnggota('searchView');
		$modelStatus=new HistClaimStatus('search');
		$modelClaim->unsetAttributes();  // clear any default values
		if (isset($_GET['HistClaim'])) {
			$modelClaim->attributes=$_GET['HistClaim'];
		}

		$this->render('view',array(
			'model'=>$this->loadModel($id),
			'modelClaim'=>$modelClaim,
			'modelAnggota'=>$modelAnggota,
			'modelStatus'=>$modelStatus,
			'id'=>$id,
		));
		
	}




	public function actionPrint($id){
		$model=$this->loadModel($id);
		

		$this->render('print',array(
			'model'=>$this->loadModel($id),
		));
	}


	public function actionExcell(){

		$jenis_laporan = $_POST['jenis_laporan'];
		$id_hist_claim = (int)$_POST['id_hist_claim'];
		$type_reg_policy = $_POST['type_reg_policy'];
		$reg_policy_id = $_POST['reg_policy_id'];

		if($type_reg_policy==1){
			$reg_policy = RegHealthPolicy::model()->findByPk($reg_policy_id);
			$noPolis = $reg_policy->policy_no;
			$periodePolis = date('d-m-Y',strtotime($reg_policy->start_periode))." s/d ".date('d-m-Y',strtotime($reg_policy->end_periode));
		}
		else{
			$reg_policy = RegHealthPolicyNon::model()->findByPk($reg_policy_id);
			$noPolis = $reg_policy->policy_no;
			$periodePolis = date('d-m-Y',strtotime($reg_policy->start_periode))." s/d ".date('d-m-Y',strtotime($reg_policy->end_periode));
		}

		$mst_client_id = (int)$reg_policy->mst_client_id;
		$namaKlien = MstClient::model()->findByPk($mst_client_id)->name;
		$limit = count(HistClaimAnggota::model()->findAll('id_hist_claim='.$id_hist_claim));


		

		/*
		$sql = "select 
		a.id_hist_claim, a.karyawan, a.tgl_claim, a.nominal, a.plan, a.peserta, a.no_reg, a.jumlah_dibayar, a.tgl_pembayaran,
		b.status, b.tgl_status, b.remarks from hist_claim_anggota a
		join hist_claim_status b on a.id=b.id_hist_claim_anggota
		where a.id_hist_claim=".$id_hist_claim." and b.id in
		(select b.id from hist_claim_anggota a
		join hist_claim_status b on a.id=b.id_hist_claim_anggota
		where id_hist_claim=".$id_hist_claim." order by b.id desc limit ".$limit.") and b.status='".$jenis_laporan."'";
		$data = Yii::app()->db->createCommand($sql)->queryAll();
		*/


		$session=new CHttpSession;
            $session->open();		
            
             if(isset($session['HistClaimReport_records']))
               {
                $model=$session['HistClaimReport_records'];
               }
               else
                 $model = HistClaimReport::model()->findAll();

            if($jenis_laporan=='1'){	 
			$limit = count(HistClaimAnggota::model()->findAll('id_hist_claim='.$id_hist_claim));
						
			//$sql = "select a.id_hist_claim, a.karyawan, a.tgl_claim, a.nominal, a.plan, a.peserta, a.no_reg, a.jumlah_dibayar, a.tgl_pembayaran from hist_claim_anggota a where id_hist_claim=".$id_hist_claim;
			$sql = "select a.id_hist_claim, a.karyawan, a.tgl_claim, a.nominal, a.plan, a.peserta, a.no_reg, a.jumlah_dibayar, a.tgl_pembayaran, b.remarks from hist_claim_anggota a
			join hist_claim_status b on a.id=b.id_hist_claim_anggota
			where a.id_hist_claim=".$id_hist_claim." and b.id in
			(select b.id from hist_claim_anggota a
			join hist_claim_status b on a.id=b.id_hist_claim_anggota
			where id_hist_claim=".$id_hist_claim." order by b.id asc limit ".$limit.")";
			$data = Yii::app()->db->createCommand($sql)->queryAll();
			$jumlah = "select sum(a.nominal) as jumlah from hist_claim_anggota a where id_hist_claim=".$id_hist_claim;
			$dataJumlah = Yii::app()->db->createCommand($jumlah)->queryRow();
			Yii::app()->request->sendFile('Lampiran Klaim.xls',
			$this->renderPartial('newKlaim', array(
				'noPolis'=>$noPolis,
				'periodePolis'=>$periodePolis,
				'namaKlien'=>$namaKlien,
				'data'=>$data,
				'dataJumlah'=>$dataJumlah,
			),true)
			);

			}

			else if($jenis_laporan=='4'){

			$limit = count(HistClaimAnggota::model()->findAll('id_hist_claim='.$id_hist_claim));
		
			$sql = "select a.id_hist_claim, a.karyawan, a.tgl_claim, a.nominal, a.plan, a.peserta, a.no_reg, a.jumlah_dibayar, a.tgl_pembayaran, b.remarks from hist_claim_anggota a
			join hist_claim_status b on a.id=b.id_hist_claim_anggota
			where a.id_hist_claim=".$id_hist_claim." and b.id in
			(select b.id from hist_claim_anggota a
			join hist_claim_status b on a.id=b.id_hist_claim_anggota
			where id_hist_claim=".$id_hist_claim." order by b.id desc limit ".$limit.") and b.status='".$jenis_laporan."'";
			$data = Yii::app()->db->createCommand($sql)->queryAll();

			$jumlah = "select sum(a.nominal) as jumlah from hist_claim_anggota a
			join hist_claim_status b on a.id=b.id_hist_claim_anggota
			where a.id_hist_claim=".$id_hist_claim." and b.id in
			(select b.id from hist_claim_anggota a
			join hist_claim_status b on a.id=b.id_hist_claim_anggota
			where id_hist_claim=".$id_hist_claim." order by b.id desc limit ".$limit.") and b.status='".$jenis_laporan."'";
			$dataJumlah = Yii::app()->db->createCommand($jumlah)->queryRow();
			

			$jumlahBayar = "select sum(a.jumlah_dibayar) as jumlah_dibayar from hist_claim_anggota a
			join hist_claim_status b on a.id=b.id_hist_claim_anggota
			where a.id_hist_claim=".$id_hist_claim." and b.id in
			(select b.id from hist_claim_anggota a
			join hist_claim_status b on a.id=b.id_hist_claim_anggota
			where id_hist_claim=".$id_hist_claim." order by b.id desc limit ".$limit.") and b.status='".$jenis_laporan."'";
			$dataJumlahBayar = Yii::app()->db->createCommand($jumlahBayar)->queryRow();


			Yii::app()->request->sendFile('Lampiran Klaim.xls',
			$this->renderPartial('pembayaranKlaim', array(
				'noPolis'=>$noPolis,
				'periodePolis'=>$periodePolis,
				'namaKlien'=>$namaKlien,
				'data'=>$data,
				'dataJumlah'=>$dataJumlah,
				'dataJumlahBayar'=>$dataJumlahBayar,
			),true)
			);

			}

			else{
			$limit = count(HistClaimAnggota::model()->findAll('id_hist_claim='.$id_hist_claim));
		
			$sql = "select a.id_hist_claim, a.karyawan, a.tgl_claim, a.nominal, a.plan, a.peserta, a.no_reg, a.jumlah_dibayar, a.tgl_pembayaran, b.remarks from hist_claim_anggota a
			join hist_claim_status b on a.id=b.id_hist_claim_anggota
			where a.id_hist_claim=".$id_hist_claim." and b.id in
			(select b.id from hist_claim_anggota a
			join hist_claim_status b on a.id=b.id_hist_claim_anggota
			where id_hist_claim=".$id_hist_claim." order by b.id desc limit ".$limit.") and b.status='".$jenis_laporan."'";
			$data = Yii::app()->db->createCommand($sql)->queryAll();

			$jumlah = "select sum(a.nominal) as jumlah from hist_claim_anggota a
			join hist_claim_status b on a.id=b.id_hist_claim_anggota
			where a.id_hist_claim=".$id_hist_claim." and b.id in
			(select b.id from hist_claim_anggota a
			join hist_claim_status b on a.id=b.id_hist_claim_anggota
			where id_hist_claim=".$id_hist_claim." order by b.id desc limit ".$limit.") and b.status='".$jenis_laporan."'";
			$dataJumlah = Yii::app()->db->createCommand($jumlah)->queryRow();
			
			Yii::app()->request->sendFile('Lampiran Klaim.xls',
			$this->renderPartial('otherKlaim', array(
				'noPolis'=>$noPolis,
				'periodePolis'=>$periodePolis,
				'namaKlien'=>$namaKlien,
				'data'=>$data,
				'dataJumlah'=>$dataJumlah,
			),true)
			);

			}



	}
		

	public function actionPdf(){
		$modelReport = new HistClaimReport;

		$jenis_laporan = $_POST['jenis_laporan'];
		$up = $_POST['up'];
		$id_hist_claim = (int)$_POST['id_hist_claim'];
		$type_reg_policy = $_POST['type_reg_policy'];
		$reg_policy_id = $_POST['reg_policy_id'];
		$pejabat = $_POST['pejabat'];
		$tgl_cetak = $_POST['tgl_cetak'];
		$tgl_bayar = $_POST['tgl_bayar'];

		if($type_reg_policy==1){
			$reg_policy = RegHealthPolicy::model()->findByPk($reg_policy_id);
		}
		else{
			$reg_policy = RegHealthPolicyNon::model()->findByPk($reg_policy_id);
		}

		$mst_client_id = (int)$reg_policy->mst_client_id;
		$mst_jns_asuransi_id = (int)$reg_policy->mst_jns_asuransi_id;
		$mst_perusahaan_asuransi_id = (int)$reg_policy->mst_perusahaan_asuransi_id;
		$tgl_cetak_input = date('d',strtotime($tgl_cetak))." ".$this->ConvertBulan(date('m',strtotime($tgl_cetak)))." ".date('Y',strtotime($tgl_cetak));
		$inisial = User::model()->findByPk(Yii::app()->user->getId())->inisial;

		$modelReport->id_hist_claim = $id_hist_claim;
		$modelReport->reg_policy_id = $reg_policy_id;
		$modelReport->type_reg_policy = $type_reg_policy;
		$modelReport->status = $jenis_laporan;
		$modelReport->createdby = Yii::app()->user->getId();
		$modelReport->updatedby = Yii::app()->user->getId();
		$modelReport->save();

		$noKlaim = $this->GetNoKlaim($modelReport->id);
		$bulan = date('m',strtotime($tgl_cetak));
		$tahun = substr(date('Y',strtotime($tgl_cetak)), -2);
		$namaKlien = MstClient::model()->findByPk($mst_client_id)->name;
		$namaUser = User::model()->findByPk(Yii::app()->user->getId())->nama;

		
		if($jenis_laporan=='1'){		
		$paramsInput = array(
			"status"=>$jenis_laporan,
			"up"=>$up,
			"id_hist_claim"=>$id_hist_claim,
			"pejabat"=>$pejabat,
			"mst_client_id"=>$mst_client_id,
			"mst_jns_asuransi_id"=>$mst_jns_asuransi_id,
			"mst_perusahaan_asuransi_id"=>$mst_perusahaan_asuransi_id,
			"tgl_cetak"=>$tgl_cetak_input,
			"inisial"=>$inisial,
			"no_klaim"=>$noKlaim,
			"bulan"=>$bulan,
			"tahun"=>$tahun,
			"nama_klien"=>$namaKlien,
			"nama_user"=>$namaUser
			);
		Yii::app()->printUtils->executeReport($paramsInput,'klaim/new_klaim.jrxml','Report Klaim - New Klaim','klaim');
		}


		if($jenis_laporan=='2'){		

			$tgl_cetak_new = date('d-m-Y',strtotime(date("Y-m-d", strtotime($tgl_cetak)) . " +2 week"));
			$tgl_cetak_new_input = date('d',strtotime($tgl_cetak_new))." ".$this->ConvertBulan(date('m',strtotime($tgl_cetak_new)))." ".date('Y',strtotime($tgl_cetak_new));

			$limit = count(HistClaimAnggota::model()->findAll('id_hist_claim='.$id_hist_claim));

		$paramsInput = array(
			"status"=>$jenis_laporan,
			"up"=>$up,
			"id_hist_claim"=>$id_hist_claim,
			"pejabat"=>$pejabat,
			"mst_client_id"=>$mst_client_id,
			"mst_jns_asuransi_id"=>$mst_jns_asuransi_id,
			"mst_perusahaan_asuransi_id"=>$mst_perusahaan_asuransi_id,
			"tgl_cetak"=>$tgl_cetak_input,
			"inisial"=>$inisial,
			"no_klaim"=>$noKlaim,
			"bulan"=>$bulan,
			"tahun"=>$tahun,
			"nama_klien"=>$namaKlien,
			"nama_user"=>$namaUser,
			"tgl_cetak_new_input"=>$tgl_cetak_new_input,
			"limit"=>(int)$limit,
			);
		Yii::app()->printUtils->executeReport($paramsInput,'klaim/tunda.jrxml','Report Klaim - Tunda','klaim');
		
		}


		if($jenis_laporan=='3'){		

			$limit = count(HistClaimAnggota::model()->findAll('id_hist_claim='.$id_hist_claim));

		$paramsInput = array(
			"status"=>$jenis_laporan,
			"up"=>$up,
			"id_hist_claim"=>$id_hist_claim,
			"pejabat"=>$pejabat,
			"mst_client_id"=>$mst_client_id,
			"mst_jns_asuransi_id"=>$mst_jns_asuransi_id,
			"mst_perusahaan_asuransi_id"=>$mst_perusahaan_asuransi_id,
			"tgl_cetak"=>$tgl_cetak_input,
			"inisial"=>$inisial,
			"no_klaim"=>$noKlaim,
			"bulan"=>$bulan,
			"tahun"=>$tahun,
			"nama_klien"=>$namaKlien,
			"nama_user"=>$namaUser,
			"tgl_cetak_new_input"=>$tgl_cetak_new_input,
			"limit"=>(int)$limit,
			);
		Yii::app()->printUtils->executeReport($paramsInput,'klaim/reklaim.jrxml','Report Klaim - Reklaim','klaim');
		
		}



		if($jenis_laporan=='4'){		

			$limit = count(HistClaimAnggota::model()->findAll('id_hist_claim='.$id_hist_claim));
			$namaAsuransi = MstPerusahaanAsuransi::model()->findByPk($mst_perusahaan_asuransi_id)->name;

			$tgl_bayar_input = date('d',strtotime($tgl_bayar))." ".$this->ConvertBulan(date('m',strtotime($tgl_bayar)))." ".date('Y',strtotime($tgl_bayar));

		$paramsInput = array(
			"status"=>$jenis_laporan,
			"up"=>$up,
			"id_hist_claim"=>$id_hist_claim,
			"pejabat"=>$pejabat,
			"mst_client_id"=>$mst_client_id,
			"mst_jns_asuransi_id"=>$mst_jns_asuransi_id,
			"mst_perusahaan_asuransi_id"=>$mst_perusahaan_asuransi_id,
			"tgl_cetak"=>$tgl_cetak_input,
			"inisial"=>$inisial,
			"no_klaim"=>$noKlaim,
			"bulan"=>$bulan,
			"tahun"=>$tahun,
			"nama_klien"=>$namaKlien,
			"nama_user"=>$namaUser,
			"tgl_cetak_new_input"=>$tgl_cetak_new_input,
			"limit"=>(int)$limit,
			"namaAsuransi"=>$namaAsuransi,
			"tgl_bayar_input"=>$tgl_bayar_input,
			);
		Yii::app()->printUtils->executeReport($paramsInput,'klaim/terima.jrxml','Report Klaim - Diterima','klaim');
		
		}



		if($jenis_laporan=='5'){		

			$limit = count(HistClaimAnggota::model()->findAll('id_hist_claim='.$id_hist_claim));
			$namaAsuransi = MstPerusahaanAsuransi::model()->findByPk($mst_perusahaan_asuransi_id)->name;

		$paramsInput = array(
			"status"=>$jenis_laporan,
			"up"=>$up,
			"id_hist_claim"=>$id_hist_claim,
			"pejabat"=>$pejabat,
			"mst_client_id"=>$mst_client_id,
			"mst_jns_asuransi_id"=>$mst_jns_asuransi_id,
			"mst_perusahaan_asuransi_id"=>$mst_perusahaan_asuransi_id,
			"tgl_cetak"=>$tgl_cetak_input,
			"inisial"=>$inisial,
			"no_klaim"=>$noKlaim,
			"bulan"=>$bulan,
			"tahun"=>$tahun,
			"nama_klien"=>$namaKlien,
			"nama_user"=>$namaUser,
			"tgl_cetak_new_input"=>$tgl_cetak_new_input,
			"limit"=>(int)$limit,
			"namaAsuransi"=>$namaAsuransi,
			);
		Yii::app()->printUtils->executeReport($paramsInput,'klaim/tolak.jrxml','Report Klaim - Ditolak','klaim');
		
		}


	}
	

	public function GetNoKlaim($idKlaim){

		$idKlaimLength = strlen($idKlaim);

		switch ($idKlaimLength) {
			case 1:$noKlaim='0000'.$idKlaim;break;
			case 2:$noKlaim='000'.$idKlaim;break;
			case 3:$noKlaim='00'.$idKlaim;break;
			case 4:$noKlaim='0'.$idKlaim;break;
			case 5:$noKlaim=$idKlaim;break;
			default:break;
		}
		return $noKlaim;
	}

	
	public function ConvertBulan($bulan){
		switch ($bulan) {
			case '01':$month='Januari';break;
			case '02':$month='Februari';break;
			case '03':$month='Maret';break;
			case '04':$month='April';break;
			case '05':$month='Mei';break;
			case '06':$month='Juni';break;
			case '07':$month='Juli';break;
			case '08':$month='Agustus';break;
			case '09':$month='September';break;
			case '10':$month='Oktober';break;
			case '11':$month='November';break;
			case '12':$month='Desember';break;
			default:break;
		}
		return $month;
	}
	

	/**
	 * Creates a new model.
	 * If creation is successful, the browser will be redirected to the 'view' page.
	 */
	public function actionCreate()
	{
		$model=new HistClaim;
		$modelStatus = new HistClaimStatus;
		$modelClient=new MstClient('searchModal');
		$modelClientNonHealth=new MstClient('searchModal2');
		$modelAnggota = new HistClaimAnggota;
		$modelHealth = new RegHealthPolicy;
		$modelNonHealth = new RegHealthPolicyNon;
		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);

		if (isset($_POST['HistClaim'])) {
			$model->attributes=$_POST['HistClaim'];
			$model->policy_no = $_POST['HistClaim']['policy_no'];
			$model->mst_client_id = $_POST['HistClaim']['mst_client_id'];
			$model->reg_policy_id = $_POST['HistClaim']['reg_policy_id'];
			$model->type_reg_policy = $_POST['HistClaim']['type_reg_policy'];
			if ($model->save()) {

			
				$arrClient = $_POST['karyawan'];
				for($i=0;$i<count($arrClient);$i++){
					if(!empty($arrClient[$i])){
						$modelHisAnggota = new HistClaimAnggota;
						$modelHisAnggota->id_hist_claim = $model->id;
						$modelHisAnggota->karyawan = $_POST['karyawan'][$i];
						$modelHisAnggota->tgl_claim = date('Y-m-d',strtotime($_POST['tgl_claim'][$i]));
						$modelHisAnggota->tgl_claim2 = date('Y-m-d',strtotime($_POST['tgl_claim2'][$i]));
						$modelHisAnggota->nominal = $_POST['nominal'][$i];
						$modelHisAnggota->plan = $_POST['plan'][$i];
						$modelHisAnggota->peserta = $_POST['peserta'][$i];
						$modelHisAnggota->no_reg = $_POST['no_reg'][$i];
						$modelHisAnggota->jumlah_dibayar = $_POST['jumlah_dibayar'][$i];
						$modelHisAnggota->tgl_pembayaran = date('Y-m-d',strtotime($_POST['tgl_pembayaran'][$i]));
						

						
						if($modelHisAnggota->save()){
							$modelHisStatus =  new HistClaimStatus;
							$modelHisStatus->id_hist_claim_anggota = $modelHisAnggota->id;
							$modelHisStatus->status = '1';
							$modelHisStatus->remarks = $_POST['remarks'][$i];
							$modelHisStatus->kelengkapan_dokumen = $_POST['kelengkapan_dokumen'][$i];
							$modelHisStatus->save();
						}
						

					}
				}
			}

			$this->redirect(array('admin'));
		}

		$this->render('create',array(
			'model'=>$model,
			'modelStatus'=>$modelStatus,
			'modelAnggota'=>$modelAnggota,
			'modelHealth'=>$modelHealth,
			'modelNonHealth'=>$modelNonHealth,
			'modelClient'=>$modelClient,
			'modelClientNonHealth'=>$modelClientNonHealth,
		));
	}

	/**
	 * Updates a particular model.
	 * If update is successful, the browser will be redirected to the 'view' page.
	 * @param integer $id the ID of the model to be updated
	 */
	public function actionUpdate($id)
	{
		$model=$this->loadModel($id);
		$modelStatus = new HistClaimStatus;
		$modelClient=new MstClient('searchModal');
		$modelClientNonHealth=new MstClient('searchModal2');
		$modelAnggota = new HistClaimAnggota;
		
			$criteria1 = new CDbCriteria;
		 	$criteria1->alias = 't';
		 	$criteria1->select = 't.id, b.nota_debet_no, b.policy_no, b.type_reg_policy, b.reg_policy_id, b.trx_date, t.karyawan, t.tgl_claim, t.tgl_claim2, t.nominal, t.plan, t.peserta, t.no_reg, t.jumlah_dibayar, t.tgl_pembayaran';
            $criteria1->join = 'join hist_claim b on t.id_hist_claim = b.id';
            $criteria1->condition = 'b.id='.$id;
		    $data = HistClaimAnggota::model()->findAll($criteria1);



		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);

		              
		if (isset($_POST['HistClaim'])) {
			$model->attributes=$_POST['HistClaim'];
			
				$arrClient = $_POST['id_anggota'];
				for($i=0;$i<count($arrClient);$i++){
					if(!empty($arrClient[$i])){
						$idAnggota = $arrClient[$i];
						

						if(trim($idAnggota)=='empty'){
						$modelHisAnggota = new HistClaimAnggota;
						$modelHisAnggota->id_hist_claim = $_POST['id_hist_claim'];
						$modelHisAnggota->karyawan = $_POST['karyawan'][$i];
						$modelHisAnggota->tgl_claim = date('Y-m-d',strtotime($_POST['tgl_claim'][$i]));
						$modelHisAnggota->tgl_claim2 = date("Y-m-d",strtotime($_POST['tgl_claim2'][$i]));
						$modelHisAnggota->nominal = $_POST['nominal'][$i];
						$modelHisAnggota->plan = $_POST['plan'][$i];
						$modelHisAnggota->peserta = $_POST['peserta'][$i];
						$modelHisAnggota->no_reg = $_POST['no_reg'][$i];
						$modelHisAnggota->jumlah_dibayar = $_POST['jumlah_dibayar'][$i];
						$modelHisAnggota->tgl_pembayaran = date('Y-m-d',strtotime($_POST['tgl_pembayaran'][$i]));
						

						
						if($modelHisAnggota->save()){
							$modelHisStatus =  new HistClaimStatus;
							$modelHisStatus->id_hist_claim_anggota = $modelHisAnggota->id;
							$modelHisStatus->status = $_POST['status'][$i];
							$modelHisStatus->remarks = $_POST['remarks'][$i];
							$modelHisStatus->kelengkapan_dokumen = $_POST['kelengkapan_dokumen'][$i];
							$modelHisStatus->save();
						}
						
						
						}					
						
						else{
						if(HistClaimAnggota::model()->updateByPk($idAnggota,array(
							'karyawan'=>$_POST['karyawan'][$i],
							'tgl_claim'=>date('Y-m-d',strtotime($_POST['tgl_claim'][$i])),
							'tgl_claim2'=>date("Y-m-d",strtotime($_POST['tgl_claim2'][$i])),
							'nominal'=>$_POST['nominal'][$i],
							'plan'=>$_POST['plan'][$i],
							'updatedby'=>Yii::app()->user->getId(),
							'updatedtime'=>date('Y-m-d H:i:s'),
							'peserta'=>$_POST['peserta'][$i],
							'no_reg'=>$_POST['no_reg'][$i],
							'jumlah_dibayar'=>$_POST['jumlah_dibayar'][$i],
							'tgl_pembayaran'=>date('Y-m-d',strtotime($_POST['tgl_pembayaran'][$i]))
							)))
						{
							$modelHisStatus =  new HistClaimStatus;
							$modelHisStatus->id_hist_claim_anggota = $idAnggota;
							$modelHisStatus->status = $_POST['status'][$i];
							$modelHisStatus->remarks = $_POST['remarks'][$i];
							$modelHisStatus->kelengkapan_dokumen = $_POST['kelengkapan_dokumen'][$i];
							$modelHisStatus->save();
						}
						
						}
						
						

					}
				}

			$this->redirect(array('admin'));
		}
		

		
		$this->render('update',array(
			'data'=>$data,
			'model'=>$model,
			'modelStatus'=>$modelStatus,
			'modelAnggota'=>$modelAnggota,
			'modelHealth'=>$modelHealth,
			'modelNonHealth'=>$modelNonHealth,
			'modelClient'=>$modelClient,
			'modelClientNonHealth'=>$modelClientNonHealth,
		));
		
	}

	/**
	 * Deletes a particular model.
	 * If deletion is successful, the browser will be redirected to the 'admin' page.
	 * @param integer $id the ID of the model to be deleted
	 */
	public function actionDelete($id)
	{
		if (Yii::app()->request->isPostRequest) {
			// we only allow deletion via POST request
			$this->loadModel($id)->delete();

			// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
			if (!isset($_GET['ajax'])) {
				$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
			}
		} else {
			throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
		}
	}

	/**
	 * Lists all models.
	 */
	public function actionIndex()
	{
		$dataProvider=new CActiveDataProvider('HistClaim');
		$this->render('index',array(
			'dataProvider'=>$dataProvider,
		));
	}

	/**
	 * Manages all models.
	 */
	public function actionAdmin()
	{
		$model=new HistClaim('search');
		$model->unsetAttributes();  // clear any default values
		if (isset($_GET['HistClaim'])) {
			$model->attributes=$_GET['HistClaim'];
		}

		$this->render('admin',array(
			'model'=>$model,
		));
	}

	/**
	 * Returns the data model based on the primary key given in the GET variable.
	 * If the data model is not found, an HTTP exception will be raised.
	 * @param integer $id the ID of the model to be loaded
	 * @return HistClaim the loaded model
	 * @throws CHttpException
	 */
	public function loadModel($id)
	{
		$model=HistClaim::model()->findByPk($id);
		if ($model===null) {
			throw new CHttpException(404,'The requested page does not exist.');
		}
		return $model;
	}

	/**
	 * Performs the AJAX validation.
	 * @param HistClaim $model the model to be validated
	 */
	protected function performAjaxValidation($model)
	{
		if (isset($_POST['ajax']) && $_POST['ajax']==='hist-claim-form') {
			echo CActiveForm::validate($model);
			Yii::app()->end();
		}
	}

	
}